package com.ctgu.examonline.controller;

import com.ctgu.examonline.entity.Answer;
import com.ctgu.examonline.entity.Major;
import com.ctgu.examonline.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 段敏杰 at 2020-08-06 21:45
 */
@RestController
@RequestMapping("/answer")
public class AnswerController {
    @Autowired
    private AnswerService answerService;

    //查询所有答案
    @RequestMapping("/list")
    public List<Answer> answerList() {
        return answerService.listAnswer();
    }

    //增加一个答案
    @RequestMapping("/save")
    public boolean saveOneAnswer(@RequestParam String ans_detail,@RequestParam Integer pro_no) {
        try {
            answerService.saveOneAnswer(ans_detail, pro_no);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    //删除一个答案
    @CrossOrigin
    @RequestMapping("/remove")
    public boolean removeOneAnswer(@RequestParam Integer ans_no) {
        try {
            answerService.removeOneAnswer(ans_no);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    //修改一个答案
    @CrossOrigin
    @RequestMapping("/update")
    public boolean updateOneAnswer(@RequestParam String ans_detail,@RequestParam Integer pro_no) {
        try {
            answerService.updateOneAnswer(ans_detail, pro_no);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    //查询一个答案
    @CrossOrigin
    @RequestMapping("/get")
    public Answer getOneAnswer(@RequestParam Integer ans_no) {
        return answerService.getOneAnswer(ans_no);
    }
}
